
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qlktcsdldc.actions.ActionHandlerConstant"%>
<%@page import="qldc.pm.qlktcsdldc.service.DanhMucSoBanNganhLocalServiceUtil"%>
<%@page import="qldc.pm.qlktcsdldc.model.DanhMucSoBanNganh"%>
<%@page import="qldc.pm.qlktcsdldc.service.NguoiDungLocalServiceUtil"%>
<%@page import="qldc.pm.qlktcsdldc.model.NguoiDung"%>
<%@ include file="../init.jsp"%>

<%
	String redirectURL = ParamUtil.getString(request, "redirect");
	PortletURL backURL = renderResponse.createRenderURL();
	backURL.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_tai_khoan.jsp");
	backURL.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_QLDC_MAN_HINH_CHINH);
	backURL.setParameter("redirect", redirectURL);
	
	PortletURL addURL = renderResponse.createRenderURL();
	addURL.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_tai_khoan.jsp");
	addURL.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_QLTK_THEM_MOI_TAI_KHOAN);
	addURL.setParameter("redirect", redirectURL);
%>
<%-- <portlet:renderURL var="addTaiKhoanURL">
	<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_tai_khoan.jsp"/>
	<portlet:param name="tabs1" value="<%=QLKTCSDLDCContants.PAGEID_QLTK_THEM_MOI_TAI_KHOAN %>" />
</portlet:renderURL> --%>
<portlet:actionURL var="QLTK_ManHinhChinhURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_TAI_KHOAN_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="QLTK_ManHinhChinhAction" />
	<portlet:param name="redirect" value="<%=backURL.toString()%>" />
	<portlet:param name="addRedirect" value="<%=addURL.toString()%>" />
</portlet:actionURL>

<h2 class="tle-Content">
	<liferay-ui:message key="quan-ly-tai-khoan" />
</h2>
<div id="<portlet:namespace/>thong-tin-chung-content">
	<form method="POST" target="_blank" action="<%=QLTK_ManHinhChinhURL.toString() %>" name="<portlet:namespace/>fmQLTKManHinhChinh" id="<portlet:namespace/>fmQLTKManHinhChinh" >
		<aui:input name="<%= Constants.CMD %>" type="hidden" />
		<%
			String tenSoBanNganh = ParamUtil.getString(request, "tenSoBanNganh");
			String tenDangNhap = ParamUtil.getString(request, "tenDangNhap");
			String hoTenNguoiDung = ParamUtil.getString(request, "hoTenNguoiDung");
		%>
		<table class="gridnormal">
			<tr>
				<td>
					<liferay-ui:message key="ten-so-ban-nganh" />
				</td>
				<td>
					<input type="text"  name="<portlet:namespace/>tenSoBanNganh" 
							id="<portlet:namespace/>tenSoBanNganh" value="<%= Validator.isNotNull(tenSoBanNganh)? tenSoBanNganh :"" %>" />
				</td>
			</tr>
	
			<tr>
				<td>
					<liferay-ui:message key="ten-dang-nhap" />
				</td>
				<td>
					<input type="text"  name="<portlet:namespace/>tenDangNhap" 
							id="<portlet:namespace/>tenDangNhap" value="<%= Validator.isNotNull(tenDangNhap)? tenDangNhap :"" %>" />
				</td>
			</tr>
			
			<tr>
				<td>
					<liferay-ui:message key="ho-ten-nguoi-dung" />
				</td>
				<td>
					<input type="text"  name="<portlet:namespace/>hoTenNguoiDung" 
							id="<portlet:namespace/>hoTenNguoiDung" value="<%= Validator.isNotNull(hoTenNguoiDung)? hoTenNguoiDung :"" %>" />
				</td>
			</tr>
	
			<tr>
				<td colspan="2">
					<input type="button" onclick="quanLyTaiKhoanSearch()" value="<liferay-ui:message key="tim-kiem" />" id="<portlet:namespace/>QKTK_timKiem" /> 
					<input type="button" onclick="quanLyTaiKhoanAdd()" value="<liferay-ui:message key="them-moi" />"  id="<portlet:namespace/>QKTK_themMoi" />
					<input type="button" onclick="quanLyTaiKhoanPrint()" value="<liferay-ui:message key="in" />"  id="<portlet:namespace/>QKTK_in" />
				</td>
			</tr>
		</table>
		
		<liferay-ui:search-container emptyResultsMessage="no-web-content-were-found" >
			<liferay-ui:search-container-results>
				<%
					results = NguoiDungLocalServiceUtil.searchNguoiDung(tenSoBanNganh, tenDangNhap, hoTenNguoiDung);
					if(Validator.isNotNull(results)){
						total = results.size();
					}else{
						total = 0;
					}
				
					pageContext.setAttribute("results", results);
					pageContext.setAttribute("total", total);
				%>
			</liferay-ui:search-container-results>
			<%
				int start = 0;
			%>
			<liferay-ui:search-container-row className="qldc.pm.qlktcsdldc.model.NguoiDung" keyProperty="IDQLKT_NguoiDung" modelVar="nguoiDung">
				<%
					String soBanNganh = "";
					if(nguoiDung.getIDQLKT_DanhMucSoBanNganh() > 0){
						DanhMucSoBanNganh danhMucSoBanNganh = DanhMucSoBanNganhLocalServiceUtil.fetchDanhMucSoBanNganh(nguoiDung.getIDQLKT_DanhMucSoBanNganh());
						if(Validator.isNotNull(danhMucSoBanNganh)){
							soBanNganh = danhMucSoBanNganh.getTenSoBanNganh();
						}
					}
					String trangThai = "";
					if(nguoiDung.getKichHoat() ){
						trangThai = LanguageUtil.get(portletConfig, request.getLocale(), "da-kich-hoat");
					}else{
						trangThai = LanguageUtil.get(portletConfig, request.getLocale(), "vo-hieu-hoa");
					}
					String chuThich = nguoiDung.getChuThich();
				%>
				<liferay-ui:search-container-column-text cssClass="aui-w3" name='STT' value="<%=String.valueOf(++start)%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10" name='<%=LanguageUtil.get(request.getLocale(), "ten-dang-nhap")%>' value="<%= nguoiDung.getTenDangNhap()%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w15 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "trang-thai")%>' value="<%=trangThai%>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "ho-va-ten")%>' value="<%= nguoiDung.getHoVaTen() %>" />
				<liferay-ui:search-container-column-text cssClass="aui-w20 txt-center" name='<%=LanguageUtil.get(request.getLocale(), "so-ban-nganh")%>' value="<%= soBanNganh %>" />
				<liferay-ui:search-container-column-text cssClass="aui-w10 txt-center" name='<%=LanguageUtil.get(request.getLocale(),"chu-thich")%>' value="<%=chuThich %>" />
				<liferay-ui:search-container-column-text cssClass="aui-Action aui-w10 txt-center" align="right">
					<liferay-ui:icon-menu message="thao-tac">
						 <portlet:renderURL var="suaURL">
							<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_tai_khoan.jsp"/>
							<portlet:param name="IDQLKT_NguoiDung" value="<%= String.valueOf(nguoiDung.getIDQLKT_NguoiDung()) %>" />
							<portlet:param name="tabs1" value="<%=QLKTCSDLDCContants.PAGEID_QLTK_SUA_THONG_TIN_CA_NHAN%>" />
						</portlet:renderURL>
						<liferay-ui:icon image="edit" message="sua" url="<%= suaURL.toString() %>" />
						
						<portlet:renderURL var="historyURL">
							<portlet:param name="mvcPath" value="/html/qlktcsdldc/quan_ly_tai_khoan.jsp"/>
							<portlet:param name="IDQLKT_NguoiDung" value="<%= String.valueOf(nguoiDung.getIDQLKT_NguoiDung()) %>" />
							<portlet:param name="tabs1" value="<%=QLKTCSDLDCContants.PAGEID_QLTK_LICH_SU_THAO_TAC_LUU_VET %>" />
						</portlet:renderURL>
						<liferay-ui:icon image="edit" message="lich-su-thao-tac-va-luu-viet" url="<%= historyURL.toString() %>" />
						
						<%
							PortletURL url = renderResponse.createRenderURL();
							url.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_tai_khoan.jsp");
							url.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_DMSBN_MAN_HINH_CHINH);
							if(nguoiDung.getKichHoat()){
						%>		
							<portlet:actionURL var="voHieuHoaNguoiDungURL" >
								<portlet:param name="redirect"  value="<%= url.toString() %>" />
								<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_TAI_KHOAN_ACTION%>" />
								<portlet:param name="<%=Constants.ACTION%>" value="voHieuHoaNguoiDung" />
								<portlet:param name="IDQLKT_NguoiDung" value="<%= String.valueOf(nguoiDung.getIDQLKT_NguoiDung()) %>" />
							</portlet:actionURL>
							<liferay-ui:icon-delete message="vo-hieu-hoa" url="<%= voHieuHoaNguoiDungURL.toString() %>" />
						<% 
							}else{
								
						%>
								<portlet:actionURL var="kichHoatNguoiDungURL" >
									<portlet:param name="redirect"  value="<%= url.toString() %>" />
									<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_TAI_KHOAN_ACTION%>" />
									<portlet:param name="<%=Constants.ACTION%>" value="kichHoatNguoiDung" />
									<portlet:param name="IDQLKT_NguoiDung" value="<%= String.valueOf(nguoiDung.getIDQLKT_NguoiDung()) %>" />
								</portlet:actionURL>
								<liferay-ui:icon-delete message="kich-hoat-lai" url="<%= kichHoatNguoiDungURL.toString() %>" />
								
								<portlet:actionURL var="deleteNguoiDungURL" >
									<portlet:param name="redirect"  value="<%= url.toString() %>" />
									<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_TAI_KHOAN_ACTION%>" />
									<portlet:param name="<%=Constants.ACTION%>" value="deleteNguoiDung" />
									<portlet:param name="IDQLKT_NguoiDung" value="<%= String.valueOf(nguoiDung.getIDQLKT_NguoiDung()) %>" />
								</portlet:actionURL>
								<liferay-ui:icon-delete message="xoa" url="<%= deleteNguoiDungURL.toString() %>" />
						<% 		
							}
						%>
												
						
					</liferay-ui:icon-menu>
				</liferay-ui:search-container-column-text> 
			</liferay-ui:search-container-row>
			<liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />

		</liferay-ui:search-container>
	</form>
</div>

<script type="text/javascript">

function quanLyTaiKhoanSearch(){
	console.log('quanLyTaiKhoanSearch');
	$('#<portlet:namespace/>fmQLTKManHinhChinh').removeAttr("target");
	$('#<portlet:namespace/>fmQLTKManHinhChinh').removeAttr("action");
	$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.TIM%>');
	$("#<portlet:namespace/>fmQLTKManHinhChinh").attr('onsubmit', 'return true;');
	$("#<portlet:namespace/>fmQLTKManHinhChinh").submit();
};
function quanLyTaiKhoanAdd(){
	console.log('quanLyTaiKhoanAdd');
	$('#<portlet:namespace/>fmQLTKManHinhChinh').removeAttr("target");
	$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.ADD%>');
	$("#<portlet:namespace/>fmQLTKManHinhChinh").attr('action', '<%=QLTK_ManHinhChinhURL.toString() %>');
	$("#<portlet:namespace/>fmQLTKManHinhChinh").submit();
	
};
function quanLyTaiKhoanPrint(){
	console.log('quanLyTaiKhoanPrint');
	showPopupConfirm('<liferay-ui:message key="ban-co-muon-luu-thong-tin" />',['Yes','No'],function(index){
		if (index == 0)
		{
			$('#<portlet:namespace/>cmd').val('<%=QLKTCSDLDCContants.IN%>');
			$("#<portlet:namespace/>fmQLTKManHinhChinh").attr('action', '<%=QLTK_ManHinhChinhURL.toString() %>');
			$("#<portlet:namespace/>fmQLTKManHinhChinh").attr('target', '_blank');
			$("#<portlet:namespace/>fmQLTKManHinhChinh").submit();
		}
	});
};
</script>